#ifndef CIRCLE_H
#define CIRCLE_H

#include <iostream>
#include <vector>
#include <math.h>
#include "point.hpp"

using namespace std;

class circle
{
public:
    point c;
    double radius = 0;
    circle() : c(0, 0) {}
    circle(point _p, double _r) : c(_p), radius(_r) {}
    void set(point _p, double _r);
    int is_in_disk(point _p);
    int is_in_disk(double _x, double _y);

    point CrossY_RightX(double _y);
    point CrossY_LeftX(double _y);
    point CrossX_BottomY(double _x);
    point CrossX_TopY(double _x);
};

void circle::set(point _p, double _r)
{
    c = _p;
    radius = _r;
}

int circle::is_in_disk(point _p) // 1表示在圆里面, 0表示不在圆内，-1表示在圆的边界上
{
    if (c.distance(_p) < radius)
        return 1;
    else if (abs(c.distance(_p) - radius) < 1e-12)
        return -1;
    else
        return 0;
}

int circle::is_in_disk(double _x, double _y)
{
    point _p(_x, _y);
    return is_in_disk(_p);
}

point circle::CrossY_RightX(double _y)
{
    point tmp;
    double delta_y = fabs(_y - c.y);
    double delta_x = sqrt(fabs(pow(radius, 2) - pow(delta_y, 2)));
    tmp.set(delta_x + c.x, _y);
    return tmp;
}

point circle::CrossY_LeftX(double _y)
{
    point tmp;
    double delta_y = fabs(_y - c.y);
    double delta_x = sqrt(fabs(pow(radius, 2) - pow(delta_y, 2)));
    tmp.set(c.x - delta_x, _y);
    return tmp;
}

point circle::CrossX_BottomY(double _x)
{

    point tmp;
    double delta_x = fabs(_x - c.x);
    double delta_y = sqrt(fabs(pow(radius, 2) - pow(delta_x, 2)));
    tmp.set(_x, c.y - delta_y);
    return tmp;
}

point circle::CrossX_TopY(double _x)
{
    point tmp;
    double delta_x = fabs(_x - c.x);
    double delta_y = sqrt(fabs(pow(radius, 2) - pow(delta_x, 2)));
    tmp.set(_x, c.y + delta_y);
    return tmp;
}

#endif